package io.renren.admin;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.Contient;
import io.renren.entity.Country;
import io.renren.service.ICountryService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;
import io.renren.utils.annotation.SysLog;
import io.renren.utils.validator.ValidatorUtils;

@RestController
@RequestMapping(value = "/qygj/country")
public class CountryController extends AbstractController {
	
	@Resource
	private ICountryService countryService;
	
	@RequestMapping("/list")
	@RequiresPermissions("qygj:country:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<Country> jobList = countryService.queryList(query);
		int total = countryService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(jobList, total, query.getLimit(), query.getPage());
		return R.ok().put("page", pageUtil);
	}
	
	@RequestMapping("/queryAllContient")
	@RequiresPermissions("qygj:country:queryAllContient")
	public R queryAllContient() {
		List<Contient> contients = countryService.queryAllContient();
		return R.ok().put("contients", contients);
	}
	
	@RequestMapping("/queryAll")
	@RequiresPermissions("qygj:country:queryAll")
	public R queryAllCountry() {
		List<Country> country = countryService.queryAll();
		return R.ok().put("country", country);
	}
	
	@RequestMapping(value = "/save")
	@RequiresPermissions("qygj:country:save")
	public R save(@RequestBody Country country) throws Exception {
		ValidatorUtils.validateEntity(country);
		countryService.save(country);
		return R.ok();
	}
	
	@RequestMapping("/update")
	@RequiresPermissions("qygj:country:update")
	public R update(@RequestBody Country country){
		ValidatorUtils.validateEntity(country);
		countryService.update(country);
		return R.ok();
	}
	
	@RequestMapping("/info/{id}")
	@RequiresPermissions("qygj:country:info")
	public R info(@PathVariable("id") Long id){
		Country country = countryService.queryObject(id);
		return R.ok().put("country", country);
	}
	
	@SysLog("删除国家信息")
	@RequestMapping("/delete")
	@RequiresPermissions("qygj:country:delete")
	public R delete(@RequestBody Long[] ids){
		countryService.deleteBatch(ids);
		return R.ok();
	}
	
}














